<?php

class Model_Orm_Show extends \Orm\Model
{
    protected static $_primary_key = array('id');
    protected static $_properties = array(
            'id',
            'movie_id',
            'auditorium_id',
            'start_time',
            'end_time',
            'movie_3d',
            'language',
            'price'
    );
    
    protected static $_belongs_to = array(
	'movie' => array(
	    'key_from' => 'movie_id',   //pareizi
	    'model_to' => 'Model_Orm_Movie',
	    'key_to' => 'id'),
	'auditorium' => array(
	    'key_from' => 'auditorium_id',
	    'model_to' => 'Model_Orm_Auditorium',
	    'key_to' => 'id')
    );
    
    protected static $_has_many = array(
	'orders' => array(
	    'key_from' => 'id',
	    'model_to' => 'Model_Orm_Order',
	    'key_to' => 'show_id',
	    'cascade_save' => true,
	    'cascade_delete' => false)
    );
    
    protected static $_table_name = 'shows';

    public static function validate($factory) {
	$val = Validation::forge($factory);

	$val->add_field('Movie_ID', 'Filmas identifikators', 'required|numeric_min[0]|numeric_max[10000]');
        $val->add_field('Start_timestamp', 'Seansa sākums', 'required|numeric_min[1000000000]|numeric_max[10000000000]');
        $val->add_field('End_timestamp', 'Seansa beigas', 'required|numeric_min[1000000000]|numeric_max[10000000000]');
        $val->add_field('Auditorium_ID', 'Auditorija', 'required|numeric_min[0]|numeric_max[40]');
        $val->add_field('Price', 'Cena', 'required|numeric_min[0]|numeric_max[1000]');
        $val->add_field('Language', 'Valoda', 'required');
        
	return $val;
    }
}
